//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#ifndef __SAGUTTARUIS__IO__H_
#define __SAGUTTARUIS__IO__H_

//== INCLUDES ========================================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/unicode/CUnicode.h"
#include <stddef.h>
#if SAGITTARIUS_LINK_WITH_GMP
#include "sagittarius/unicode/GMPUnicode.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if SAGITTARIUS_IS_POSIX_VAR
    #define SG_WRITE(fd, buf) sg_write(fd, (void*)buf, sizeof(buf)-1) //EDIT: I guess Unix does too!!
#elif SAGITTARIUS_PLATFORM == SAGITTARIUS_PLATFORM_WIN
    #define SG_WRITE(fd, buf) sg_write(fd, buf, sizeof(buf)-1) //I guess Windows includes the null char
#endif

void sg_write(int fd, void* buf, size_t nbytes);

//Integers
void sg_writeInt(int fd, int n);
void sg_writeUInt(int fd, unsigned int n);
void sg_writeInt64(int fd, int64 n);
void sg_writeUInt64(int fd, uint64 n);
void sg_writeUInt32Hex(int fd, uint32 n);
void sg_writeUInt64Hex(int fd, uint64 n);

void sg_writeInt2(int n); //2 is for stderr
void sg_writeUInt2(unsigned int n);

//Raw memory
void sg_writeMemSegHex(int fd, void* addr, size_t nbytes);

//Strings
void sg_writeCStr(int fd, const char* str);
void sg_writeUStr(int fd, const UnicodeCChar* buf);
void sg_writeUStrl(int fd, const UnicodeCChar* buf, const size_t len);
void sg_writeUChar(int fd, const UnicodeCChar x);

#if SAGITTARIUS_LINK_WITH_GMP
void sg_writeGMPUStr(int fd, GMPUnicodeChar* buf);
void sg_writeGMPUStrl(int fd, GMPUnicodeChar* buf, const size_t len);
#endif

//Pointers
void sg_writePtr(int fd, void* ptr);

#ifdef __cplusplus
}//extern "C"
#endif

#endif
